<?php

/**
 * @author      Nguyen Duc Thuan <me@ndthuan.com>
 * @copyright   Copyright (c) 2009 Nguyen Duc Thuan <me@ndthuan.com>
 * @version     $Id: List.php 12 2009-11-03 03:17:46Z thuan.nguyen $
 */

class Fete_List
{
    protected $_list = array();
    protected $_count   = 0;

    public function __construct()
    {
        $list = func_get_args();
        $this->_list = $list;
        $this->_count = count($list);
    }

    /**
     *
     * @param mixed $item
     * @return Fete_List
     */
    public function &append($item)
    {
        $this->_list[] = $item;
        $this->_count++;
        return $this;
    }

    /**
     *
     * @param array $items
     * @return Fete_List
     */
    public function &appendMultiple($items)
    {
        $this->_list = array_merge($this->_list, $items);
        $this->_count += count($items);
        return $this;
    }

    /**
     *
     * @param mixed $item
     * @return Fete_List
     */
    public function &prepend($item)
    {
        $this->_list = array_merge(array($item), $this->_list);
        $this->_count++;
        return $this;
    }

    /**
     *
     * @param array $items
     * @return Fete_List
     */
    public function &prependMultiple($items)
    {
        $this->_list = array_merge($items, $this->_list);
        $this->_count += count($items);
        return $this;
    }

    /**
     *
     * @param integer $key
     * @return mixed
     */
    public function get($key)
    {
        return isset($this->_list[$key]) ? $this->_list[$key] : null;
    }

    /**
     *
     * @return array
     */
    public function getAll()
    {
        return $this->_list;
    }

    public function length()
    {
        return $this->_count;
    }
}